package top.korori.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.korori.entity.SysRoleUser;
import top.korori.mapper.SysRoleUserMapper;
import top.korori.service.SysRoleUserService;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 
 * 用户角色关联 服务实现类
 * 
 *
 * @author korori
 * @since
 */
@Service
public class SysRoleUserServiceImpl extends ServiceImpl<SysRoleUserMapper, SysRoleUser> implements SysRoleUserService {

    @Override
    public List<Long> getRoleIdsByUserId(Long userId) {
        LambdaQueryWrapper<SysRoleUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysRoleUser::getUserId,userId);
        List<SysRoleUser> roleUsers = this.list(queryWrapper);
        return roleUsers.stream().map(SysRoleUser::getRoleId).collect(Collectors.toList());
    }

    @Override
    public void delByUserId(Long userId) {
        LambdaQueryWrapper<SysRoleUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysRoleUser::getUserId,userId);
        this.remove(queryWrapper);
    }
}
